import BaseService from '../BaseService'
import factory from '../serviceFactory'
import SystemConstant from '@/constants/System'

class LoginService extends BaseService {
  /**
   * login({userName,password,rememberMe})
   */
  login = factory.makePost('/api/system/login', {successW: false})

  /**
   * logout()
   */
  logout = factory.makePost('/api/system/logout', {successW: false})

  /**
   * weChatLogin()
   */
  weChatLogin () {
    const redirect = SystemConstant.WX_REDIRECT_URI
    const appID = SystemConstant.WX_APP_ID
    const params = []
    params.push('redirect_uri=' + redirect)
    params.push('appid=' + appID)
    params.push('response_type=code')
    params.push('scope=snsapi_userinfo')
    params.push('#wechat_redirect')
    const path = 'https://open.weixin.qq.com/connect/oauth2/authorize?' + params.join('&')
    window.location.href = path
  }

  /**
   * bindWx({userName,password})
   */
  bindWx = factory.makePost('/api/wx/bind')

  /**
   * isLogined()
   */
  isLogined = factory.makeGet('/api/system/logined', {failedW: false, canCancel: false})

  /**
   * 获取图片服务地址
   */
  getFileServerUrl = factory.makeGet('/api/system/getFileServerUrl', {failedW: false})

  /**
   * 获取系统参数
   */
  getSysConfig = factory.makeGet('/api/sys/config', {failedW: false})
}

export default new LoginService()
